package com.itheima.d04_xml_write;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * 目标：了解XML写出文件的步骤
 */
public class Test {

    public static void main(String[] args) throws IOException {
        //1.拼接xml格式的字符串数据：StringBuilder 效率高 /StringBuffer 效率低
        StringBuilder sb = new StringBuilder();
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n")
                .append("<users id = '1001'>\r\n")

                    .append("\t<user>\r\n")
                        .append("\t\t<name id='1' num='1'>张三</name>\r\n")
                        .append("\t\t<age>18</age>\r\n")
                        .append("\t\t<sex>男</sex>\r\n")
                        .append("\t\t<address>济南</address>\r\n")
                    .append("\t</user>\r\n")


                    .append("\t<user>\r\n")
                        .append("\t\t<name id='1' num='1'>张三</name>\r\n")
                        .append("\t\t<age>18</age>\r\n")
                        .append("\t\t<sex>男</sex>\r\n")
                        .append("\t\t<address>济南</address>\r\n")
                    .append("\t</user>\r\n")

                .append("</users>");

        //2.通过IO流。写入到指定的xml文件中
        BufferedWriter bw = new BufferedWriter(
                new FileWriter("day12_properties_xml_log\\src\\com\\itheima\\d04_xml_write\\users.xml"));

        bw.write(sb.toString());
        bw.close();//带有缓冲区的流，使用完毕后，记得刷新缓冲器，资源释放

        System.out.println("写入完毕！");
    }
}










